package cn.jekun.shop.app.action;

import javax.annotation.Resource;

import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.shop.common.service.OpenedCityService;

/**
 * 已开通城市
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class OpenedCityAction extends AppBaseAction{
	@Resource(name = OpenedCityService.BEAN_NAME)
	protected OpenedCityService openedCityService;
	/**
	 * 已开通城市列表
	 * @return
	 */
	public String openedCityList(){
		JSONObject jsonObject = null;
		try {
			jsonObject = this.openedCityService.queryCitys();
		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 获取城市编码
	 * @return
	 */
	public String getCityCode(){
		JSONObject jsonObject = null;
		try {
			String cityName = this.request.getParameter("cityName");//城市名
			this.validateSign(cityName);
			jsonObject = openedCityService.getCityCodeByCityName(cityName);
		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}

}
